#ifndef __EKF_VMEM_I_H__
#define __EKF_VMEM_I_H__

extern struct segdesc_s gdt[GDT_COUNT];

int vmem_init(void);

int vmem_init_ap(physaddr_t cr3);
int vmem_post_fix(void);
int vmem_init_cpupriv(void);


/* simple function for getting and setting the current vpt */
void         vpt_set(void *vaddr, uint32_t pte);
ptab_entry_t vpt_get(void *vaddr);

/* control the temp page for current kstack */
void        *set_tpage(physaddr_t addr);

void mmap_set(void *vaddr, physaddr_t paddr,  int write, int user);
void mmap_get(void *vaddr, physaddr_t *paddr, int *write, int *user);

/* These macros define a simple method for using tpage space,
   all the data should not exceed the 4K page boundary */
#define BEGIN_TPAGE(ADDR, VAR)					  \
	 { uint32_t __old = vpt_get((void *)KTMP);	\
	   VAR = set_tpage(ADDR)

#define EXIT_TPAGE vpt_set((void *)KTMP, __old)
#define END_TPAGE  vpt_set((void *)KTMP, __old); }

/* a universe function for vpt management */
#define    FA_COW 1
#define	   FA_AWA 2
#define    fix_addr(args ...) __fix_addr(0, args)
int        __fix_addr(int verbose, void *addr, ptab_entry_t *create, ...);

/* Create a new sketch vpt */
physaddr_t vmem_vpt_new(int new_share);


#endif
